<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<body>
	<fieldset class="layui-elem-field layui-field-title site-title">
		<legend>
			<a name="fixbar" style="font-size: 16px; color: #ce2424;"><i class="fa fa-clipboard"></i>课程评价</a>
		</legend>
	</fieldset>
	<table class="layui-hide" id="dictionary" lay-filter="dictionary"></table>
	<script type="text/html" id="barDemo">
  			<a class="layui-btn layui-btn-xs layui-btn-normal layui-icon layui-icon-set-fill" data-method="notice" lay-event="edit"> 查看</a>
	</script>
	<script type="text/html" id="toolbarDemo">
  			<form class="layui-form" action="save" id="myForm" method="post" lay-filter="stuform">
		<input type="text" style="display: none;" />
			<div class="layui-inline">
				<label class="layui-form-label" style="width:100px">查询内容:</label>
				<div class="layui-input-block">
					<input type="text" name="search" id="searchvalue" value="${search}" onkeypress="return onKeyPress(event)" class="layui-input" />
				</div>
			</div>
			<div class="layui-inline">
				<button class="layui-btn layui-btn-sm" onclick="searchs()" style="margin-left: 16px"><i class="fa fa-search"></i>查询</button>
			</div>
		</form>
	</script>
	<script type="text/javascript">
		var widthbody = $(document.body).outerWidth(true);
		var width = parseInt(widthbody)-parseInt(100) + "px";
		var titlename = $("#titlename").val();
		var option={
			elem:'#dictionary',
			title:'课程评价',
			path:'courseEvaluation',
			addurl:'edit',
			id:"dictionary",
			toolbar:'#toolbarDemo',
			limit: 20,
			defaultToolbar: ['filter', 'exports'],
			cols: [[
				{field: 'tbCurriculumCourseName', title: '课程名称',align:'center'},
				{field: 'teacherName', title: '教师',align:'center'},
				{field: 'grads', hide: true,title: '分数（分数*权重）',align:'center'},
				{field: 'isevaluate', title: '是否评价',align:'center', templet: function(d){
					return d.isevaluate? '已评价': '未评价';
				}},
				{fixed: 'right', title: '操作',align:'center',width:100, templet: function(d){
					 var html = "";
					if(d.isevaluate == 1){
						html = '<a class="layui-btn layui-btn-xs layui-btn-normal layui-icon layui-icon-survey" data-method="notice" lay-event="evaluation">&nbsp;&nbsp;评价</a>';
					}else if(d.isevaluate == 2){
						html = '<a class="layui-btn layui-btn-xs layui-btn-primary" data-method="notice" lay-event="Toview"><i class="fa fa-eye"></i>查看</a>';
					}else if(d.isevaluate == 3){
						html = '<a class="layui-btn layui-btn-disabled layui-btn-xs"><i class="fa fa-hourglass-2"></i>待评价</a>';
					}else if(d.isevaluate == 4){
						html = '<a class="layui-btn layui-btn-disabled layui-btn-xs"><i class="fa fa-low-vision"></i>已过期</a>';
					}
					return html;
				}}
			]] 
		}
		var currRow='${param.currRow==null?null:param.currRow}';
		var limit=${param.limit==null?'null':param.limit};
		var page=${param.page==null?'null':param.page};
		var classTable=new LayUiTable(option,currRow,limit,page);
		classTable.init();
		function searchs(){
			classTable.search();
		}
		function empty(){
			classTable.empty();
		} 
		function onKeyPress(event){
			if(event.keyCode==13){
				searchs();
			}
		}
		
		layui.use('table', function(){
			var table = layui.table;
			table.on('tool(dictionary)', function(obj){
			    var data = obj.data;
			    if(obj.event === 'Toview'){
			    	$.post("courseEvaluation/toview", {uuid: obj.data.id}, function(data){
						layui.use('layer', function(){
							layer.open({
								title: obj.data.tbCurriculumCourseName,
								type: 1,
	    	      				shade: 0.3,
	    	      				shadeClose:true,
	    	      				maxmin: true,
	    	      				content: data,
	    	      				area: ['80%', '80%'],
	    	      				btn: ['确定','关闭'],
	    	      				yes:function(){
	    	      					layer.closeAll();
	    	      				},
	    	      				//弹出层打开回调
	    	      				
							})
						});
					});
			    }
			    if(obj.event === 'evaluation'){
			    	
			    	$.post("courseEvaluation/evaluation", {uuid: obj.data.id}, function(data){
						layui.use('layer', function(){
							layer.open({
								title: "评价课程："+obj.data.tbCurriculumCourseName  ,
								type: 1,
	    	      				shade: 0.3,
	    	      				maxmin: true,
	    	      				content: data,
	    	      				area: ['80%', '60%'],
	    	      				btn: ['确定评价'],
	    	      				yes:function(){
	    	      					
	    	      				},
	    	      				//弹出层打开回调
	    	      				success: function(layero, index){
	    	      					layui.use('form', function(){
	    	      						var form=layui.form;
						    			layero.addClass('layui-form');
							    		var submitBtn=layero.find('.layui-layer-btn0');
							    		submitBtn.attr('lay-filter','formVerify').attr('lay-submit','');
							    		form.on('submit(formVerify)',function(data){
							    			//console.info(data.field.grade0);
							    			//var arr = Object.keys(data.field); 
							    			//console.log(arr[0]);  
							    		    console.info(data);
							    			var f = true;
							    			var result = [];
							    			var resultuuid = [];
							    			var evaluation = [];
							    			var suggest = [];
							    			$.each(data.field,function(key,vales){
							    				console.info(vales);
							    				if(vales == ""&&key!="suggest"){
							    					layer.alert('您还未全部打分哦，请认证核对打分情况！');
							    					f = false;
							    					return false;
							    				}else{
							    					if(key!="evaluation"&&key!="suggest"){
								    					result.push(vales);
								    					resultuuid.push(key);
							    					}else if(key=="evaluation"){
							    						evaluation.push(data.field.evaluation);
							    					}else if(key=="suggest"){
							    						suggest.push(data.field.suggest)
							    					}
							    				}
							    			}); 
							    			if(f){
							    				
							    				layer.confirm('提交以后不可进行修改哦!<br/>确认提交？', function(index){
							    					$.ajax({
							    		                type: 'POST',
							    		                url: "courseEvaluation/evaluationgradsave",
							    		                contentType: "application/json;charset=UTF-8",
							    		                data:JSON.stringify({"result":result,"resultuuid":resultuuid,"evaluation":evaluation,"suggest":suggest}),
							    		                success: function(data){
							    		                	if(data.success){
							    		                		layer.closeAll();
									    						table.reload('dictionary',{
									    							url:'courseEvaluation/page'
									    						});
									    					}
									    					layer.msg(result.msg,{offset:'rb'});
							    		                }
							    		            })
							    							    	  		
							    		    	 }); 
								    								    				
							    			}
							    		});
	    	      					})
	    	      				}
							})
						});
					});
			    }
			});
		});
		
	</script>
	
</body>
